package com.atguigu.springcloud.controller;

import com.atguigu.springcloud.config.RestConfig;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import javax.annotation.Resource;

/**
 * Created with IntelliJ IDEA.
 * ClassName: OrderNacosController
 * Package: com.atguigu.springcloud.controller
 * Description:
 * User: fzykd
 *
 * @Author: LQH
 * Date: 2023-11-07
 * Time: 15:44
 */

@RestController
@Slf4j
public class OrderNacosController {

    @Resource
    private RestTemplate restTemplate;

    @Value("${service-url.nacos-user-service}")
    private String serverURL;

    @GetMapping("/consumer/payment/nacos/{id}")
    public String paymentInfo(@PathVariable("id") Long id) {
        //服务的消费者 去消费9001和9002服务的提供则
        //演示Nacos自带负载均衡
        //证明天生自带负载均衡 整合了Ribbon 就可以用RestTemplate
        return restTemplate.getForObject(serverURL + "/payment/nacos/" + id, String.class);

    }


}
